package com.deltabravomedia.theoldtoad;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Contacts;
import android.text.util.Linkify;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class Contact extends Activity {
	private final static String add =   "Addr:\tThe Old Toad\n" +
			 							"\t\t\t277 Alexander Street\n" +
			 							"\t\t\tRochester, New York\n" +
			 							"\t\t\t14607";
	private final static String phone = "Tel:\t\t585.232.2626\n" +
			 					        "Fax:\t585.232.9019";
	private final static String email =  "Email:\tinfo@TheOldToad.com";
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.contact);
        this.setTitle("The Old Toad : Contact");

        // Capture our button from layout
        Button callButton = (Button)findViewById(R.id.call_button);
        // Register the onClick listener with the implementation above
        callButton.setOnClickListener(mCallListener);

        // Capture our button from layout
        Button addButton = (Button)findViewById(R.id.add_button);
        // Register the onClick listener with the implementation above
        addButton.setOnClickListener(mAddListener);
        
        TextView tv = (TextView)findViewById(R.id.address);
        tv.setText(add);
        TextView tv2 = (TextView)findViewById(R.id.phone);
        tv2.setText(phone);
        TextView tv3 = (TextView)findViewById(R.id.email);
        tv3.setText(email);
        Linkify.addLinks(tv3, Linkify.EMAIL_ADDRESSES);
    
    }
    
 // Create an anonymous implementation of OnClickListener
    private OnClickListener mCallListener = new OnClickListener() {
        public void onClick(View v) {
        	String phoneNumber = "15852322626";
        	Uri uri = Uri.fromParts("tel", phoneNumber, null);

        	Intent callIntent = new Intent(Intent.ACTION_CALL, uri);
        	callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        	startActivity(callIntent);
        }
    };
    
    // Create an anonymous implementation of OnClickListener
    private OnClickListener mAddListener = new OnClickListener() {
        public void onClick(View v) {
        	Intent addContactIntent = 
        			new Intent(Contacts.Intents.Insert.ACTION, Contacts.People.CONTENT_URI);
        	addContactIntent.putExtra(Contacts.Intents.Insert.NAME, "The Old Toad"); 
        	addContactIntent.putExtra(Contacts.Intents.Insert.PHONE, "15852322626"); 
        	addContactIntent.putExtra(Contacts.Intents.Insert.POSTAL, "277 Alexander Street");
        	addContactIntent.putExtra(Contacts.Intents.Insert.POSTAL_TYPE, Contacts.ContactMethodsColumns.TYPE_WORK);
        	addContactIntent.putExtra(Contacts.Intents.Insert.EMAIL, "info@TheOldToad.com"); 
        	startActivity(addContactIntent);
        }
    };    
}